<%@ page import="com.lovebridge.model.User" %>
<%@ page import="com.lovebridge.SystemManager" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8" errorPage="/error.jsp"%>
   <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
    String userName=request.getParameter("userName");
    String password=request.getParameter("password");
    if (userName!=null&&password!=null) {
        User user= SystemManager.getPersist().read(User.class, "select * from user where userName=?", userName);
        if (user==null) {
            request.setAttribute("message","找不到指定用户。");
        } else if (!user.getPassword().equals(password)) {
            request.setAttribute("message","用户名和密码不匹配。");
        } else {
            session.setAttribute("user",user);
            response.sendRedirect("index.jsp");
        }
    }
%>
   <jsp:include page="/header.jsp" flush="true" />
               <form id="login" name="login"
                   action="login.jsp" method="post">
                   <div class="search">
                       <ul>
                           <li class="title">
                               登录
                           </li>
                           <li>
                               <c:if test="${!empty message}">
                                   <font color="RED"><c:url value="${message}" /> </font>
                               </c:if>
                           </li>
                           <li>
                               <b>用户名: </b>
                               <input type="text"   name="userName"
                                   id="userName" />
                           </li>
                           <li>
                               <b>密码: </b>
                               <input type="password" value="" name="password" id="password" />
                           </li>
                           <li>
                               <input type="submit" value="登录" /> &nbsp;&nbsp;&nbsp;<input type="button" value="注册" onclick="location.href='register.jsp'" />
                           </li>
                       </ul>
                   </div>
               </form>
   <jsp:include page="/footer.jsp" flush="false" />
